// pages/tabbar/home/index.ts
import { formatCurrentTime, getTodayWhatDay } from "../../../utils/timeUtil";
import { getIndexInfo } from '@/api/tabbar/index/index'
Page({
  /**
   * 页面的初始数据
   */
  data: {
    todayDate: "", // 今天日期
    today: "", // 今天星期几
    surplusQuota: <number | null>0, // 剩余额度
    todayPay: <number>0,
    menuList: [
      { label: "快捷设置", icon: "fast", router: "" },
      { label: "财产管理", icon: "property", router: "property" },
      { label: "账单管理", icon: "plan", router: "bill" },
      { label: "成员管理", icon: "person", router: "member" },
      { label: "待办管理", icon: "backlog", router: "" },
    ],
  },
  // 获取今天日期
  getTodayDate() {
    const todayDate = formatCurrentTime("yyyy-mm-dd");
    const today = getTodayWhatDay();
    this.setData({
      todayDate,
      today,
    });
  },
  handleMenu(e: WechatMiniprogram.CustomEvent) {
    const { router } = e.currentTarget.dataset;
    wx.navigateTo({
      url: `/pages/${router}/index/index`,
    });
  },
  // 获取首页数据
  getInfo() {
    getIndexInfo().then((res) => {
      const { budget: surplusQuota, todayPay} = res.data
      this.setData({
        surplusQuota,
        todayPay
      })
    })
  },
  // 设置预算
  handleSetBudgetTap() {
    wx.navigateTo({ url: '/pages/property/budget/index'})
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
   
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
    this.getTodayDate();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    if (typeof this.getTabBar === "function" && this.getTabBar()) {
      this.getTabBar().setData({
        selected: 0,
      });
    }
    this.getInfo()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {},

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {},

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {},

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {},
});
